package com.yuezhi.producer.dlx.config;

import com.yuezhi.producer.constant.QueueConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class dlxConfig {
    private static final Integer TIME = 60 * 1000;
    @Bean
    Queue dlxSendQueue() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-message-ttl", TIME);
        args.put("x-dead-letter-exchange", QueueConstant.DLX_RECEIVE_EXCHANGE);
        args.put("x-dead-letter-routing-key", QueueConstant.DLX_ROUTE_KEY);
        return QueueBuilder.durable(QueueConstant.DLX_SEND_QUEUE).withArguments(args).build();
       // return new Queue(QueueConstant.DLX_SEND_QUEUE, true, false ,false, args);
    }

    @Bean
    DirectExchange dlxSendExchange() {
        return new DirectExchange(QueueConstant.DLX_SEND_EXCHANGE, true , false);
    }

    @Bean
    Binding dlxSendBinding() {
        return BindingBuilder.bind(dlxSendQueue()).to(dlxSendExchange()).with(QueueConstant.DLX_SEND_QUEUE);
    }

    /*@Bean
    Queue dlxReceiveQueue() {
        return new Queue(QueueConstant.DLX_RECEIVE_QUEUE, true, false, false);
    }

    @Bean
    DirectExchange dlxReceiveExchange() {
        return new DirectExchange(QueueConstant.DLX_RECEIVE_EXCHANGE, true, false);
    }

    @Bean
    Binding dlxReceiveBinding() {
        return BindingBuilder.bind(dlxReceiveQueue()).to(dlxReceiveExchange()).with(QueueConstant.DLX_ROUTE_KEY);
    }*/
}
